package com.sluggard.mp.model.entity;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.springframework.format.annotation.DateTimeFormat;

import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * @author lizheng
 * @since 2024.4.17
 */
@Data
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
public abstract class StandardAuditEntity extends IdEntity implements Serializable {

    /**
     * 创建人，员工id
     */
    @TableField(value = "create_by", keepGlobalFormat = true, fill = FieldFill.INSERT)
    private Long createBy;

    /**
     * 更新人，员工id
     */
    @TableField(value = "update_by", keepGlobalFormat = true, fill = FieldFill.INSERT_UPDATE)
    private Long updateBy;

    @Schema(description = "创建时间")
    @TableField(value = "create_time", fill = FieldFill.INSERT)
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime createTime;

    @Schema(description = "最后修改时间")
    @TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime updateTime;


    @Schema(description = "是否删除{0:正常,1:删除}")
    @TableField(value = "deleted", fill = FieldFill.INSERT)
    @JsonIgnore
    @TableLogic
    private Boolean deleted;

    @Schema(description = "版本号")
    @Version
    @TableField(value = "version", fill = FieldFill.INSERT)
    private Long version;
}
